/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import MaDictRadio from "@/components/ma-dict-picker/ma-dict-radio.vue";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { page as getDevicesList } from "$/attractions/inspection/api/inspectionDevices.ts";
import { concat } from "lodash-es";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "记录ID",
      prop: "inspection_record_id",
      render: () => MaDictSelect,
      renderProps: { multiple: false },
      itemProps: { rules: [{ required: true, message: "请输入记录ID" }] },
    },
    {
      label: "设备ID",
      prop: "device_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getDevicesList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.name || `设备${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择设备",
        clearable: true,
        multiple: false,
      },
      itemProps: { rules: [{ required: true, message: "请选择设备" }] },
    },
    {
      label: "图片",
      prop: "photo",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "图片" }) },
    },
    {
      label: "状态",
      prop: "status",
      render: () => MaDictRadio,
      renderProps: {
        data: [
          { label: "正常", value: 1 },
          { label: "异常", value: 2 },
        ],
        placeholder: "请选择状态",
      },
      itemProps: { rules: [{ required: true, message: "请选择状态" }] },
    },
  ]);
}
